package com.fenxiangtech.mall.manager;

import com.fenxiangtech.mall.dao.UserAddressDAO;
import com.fenxiangtech.mall.model.UserAddress;
import com.fenxiangtech.mall.model.qc.UserAddressQC;
import com.fenxiangtech.mall.model.qc.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class UserAddressManager {

    @Autowired
    private UserAddressDAO userAddressDAO;

    public List<UserAddress> queryUserAddress(UserAddress userAddress, Integer pageIndex , Integer pageSize){
        Page page = new Page(pageIndex,pageSize);
        UserAddressQC qc  = new UserAddressQC();
        qc.setPage(page);
        BeanUtils.copyProperties(userAddress,qc);
        List<UserAddress> userAddresss = userAddressDAO.listUserAddress(qc);
        return userAddresss;
    }

    public Long countUserAddress(UserAddress userAddress){
        UserAddressQC qc  = new UserAddressQC();
        BeanUtils.copyProperties(userAddress,qc);
        Long count = userAddressDAO.countUserAddress(qc);
        return count;
    }

    public int saveUserAddress(UserAddress userAddress){

        if(userAddress.getId()!=null){
            return userAddressDAO.updateUserAddress(userAddress);
        }else {
//            userAddress.setCreateTime(new Date());
            return userAddressDAO.insertUserAddress(userAddress);
        }

    }
    public int deleteUserAddress(Long id){

        return userAddressDAO.deleteUserAddressById(id);

    }



}
